package com.example.hasee.zhcd.Adapters;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.hasee.zhcd.Activities.TongJi.SchlDetailActivity;
import com.example.hasee.zhcd.R;
import com.example.hasee.zhcd.Util.GlobalParameter;

import java.util.ArrayList;
import java.util.HashMap;


/**
 * Created by hasee on 2017/9/13.
 */

public class CshlAdapter extends BaseAdapter {
    private HashMap<String, String> map = (HashMap<String, String>) GlobalParameter.get("loginmap");
    private ArrayList<HashMap<String, String>> list;
    private LayoutInflater itemInflater;
    private Context context;
    private Holder holder;

    public CshlAdapter(Context context, ArrayList<HashMap<String, String>> list) {
        this.context = context;
        this.list = list;
        this.itemInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            holder = new Holder();
            convertView = itemInflater.inflate(R.layout.schl_list_item, null);
            holder.fpm = (TextView) convertView.findViewById(R.id.fpm);
            holder.fcgs = (TextView) convertView.findViewById(R.id.fcgs);
            holder.fsc = (TextView) convertView.findViewById(R.id.fsc);
            holder.fhl = (TextView) convertView.findViewById(R.id.fhl);
            holder.fzg = (TextView) convertView.findViewById(R.id.fzg);
            holder.detail = (TextView) convertView.findViewById(R.id.detail);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        holder.fpm.setText((String) list.get(position).get("fpm"));
        holder.fcgs.setText((String) list.get(position).get("fcgs"));
        holder.fsc.setText((String) list.get(position).get("fsc"));
        holder.fhl.setText((String) list.get(position).get("fhl"));
        holder.fzg.setText((String) list.get(position).get("fzg"));
        holder.detail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, SchlDetailActivity.class);
                intent.putExtra("strCGS", list.get(position).get("fcgscode"));
                intent.putExtra("strKSSJ", list.get(position).get("strKSSJ"));
                intent.putExtra("strJSSJ", list.get(position).get("strJSSJ"));
                context.startActivity(intent);
            }
        });
        return convertView;
    }

    class Holder {
        private TextView fpm;
        private TextView fcgs;
        private TextView fsc;
        private TextView fhl;
        private TextView fzg;
        private TextView detail;
    }
}
